function X_filtered = ecg_smooth(X,Order=5,Windows = 51,Samp_freq=550)
%% Smoothing filter for ECG
% Usage:
% X_filtered = ecg_smooth(X);
% X_filtered = ecg_smooth(X, Order);
% X_filtered = ecg_smooth(X, Order, Windows);
% X_filtered = ecg_smooth(X, Order, Windows, Samp_freq);
%
% Inputs:
% X: Discrete time signal
% Order: Order of fitting polynomial (<Window)
% Window: window size (odd no.)
% 
% Outputs:
% X_filtered: filtered signal
%
%
% Debug mode:
% If output variable is not specified, debug mode will automatically turned on.
% Filtered signal and Frequencncy response of the notch filter will be drawn in new figure window.
%
% Copyright by Group 8

% Savitzky-Golay filtering
    X_filtered = sgolayfilt(X, Order, Windows);

%Debug mode:
if(!nargout)
t = [0:length(X)-1]/Samp_freq;
subplot(2,1,1), plot(t,X,';Raw signal;'),xlim([15 25])
ylabel('Voltage / V')
subplot(2,1,2), plot(t,X_filtered,';Filtered signal;'),xlim([15 25])
xlabel('time / s');
end

end


